package com.xyoto.community.service.impl;

import com.xyoto.community.utils.RedisCommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class FanFollowRedisImpl {

    @Autowired
    private RedisCommonUtils redisCommonUtils;

    /**
     * 关注存入redis
     * @param userId
     * @param targetId
     */
    public void saveFanRedis(Integer userId, int targetId) {
        String fanRedisKey = getFanRedisKey(userId);
        redisCommonUtils.sSet(fanRedisKey,targetId);
        log.info("存入redis中的值后" + redisCommonUtils.sGet(fanRedisKey));
    }

    /**
     * 取消关注删除redis中的值
     * @param userId
     * @param targetId
     */
    public void removeFanFollow(Integer userId, int targetId) {
        String fanRedisKey = getFanRedisKey(userId);
        redisCommonUtils.setRemove(fanRedisKey,targetId);
        log.info("删除redis中对应的值后" + redisCommonUtils.sGet(fanRedisKey));
    }

    /**
     * 生成redis关注Key
     * @param userId
     * @return
     */
    public static String getFanRedisKey(Integer userId){
        return "fan" + userId.toString();
    }
}
